package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.TenderListEntity;
import com.sgb.kjwl.view.ui.adapter.pick.PickHomeHotChildHeadAdapter;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;
/**
 * @author: 王彬臣
 * @date: 2021/10/13
 * @Description: 工队工程分包Adapter
 */
public class PackerHallBidingAdapter extends BaseRecycleAdapter<TenderListEntity> {

    private String type = "0";
    private RecyclerView recyclerView;
    private LinearLayout noList;
    private PickHomeHotChildHeadAdapter pickHomeHotChildHeadAdapter;
    private IChildClick iChildClick;


    public PackerHallBidingAdapter(Context context, List<TenderListEntity> datas) {
        super(context, R.layout.item_pick_hall_biding, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final TenderListEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        recyclerView = holder.itemView.findViewById(R.id.child_rv);
        noList = holder.itemView.findViewById(R.id.no_list);


        if (entity.getGoodsHeaders() == null || entity.getGoodsLists() == null) {
            recyclerView.setVisibility(View.GONE);
            noList.setVisibility(View.VISIBLE);
        } else {
            if (entity.getGoodsHeaders().length == 0 && entity.getGoodsLists().length == 0) {
                recyclerView.setVisibility(View.GONE);
                noList.setVisibility(View.VISIBLE);
            } else {
                recyclerView.setVisibility(View.VISIBLE);
                noList.setVisibility(View.GONE);
                pickHomeHotChildHeadAdapter = new PickHomeHotChildHeadAdapter(context, entity.getGoodsHeaders(), entity.getGoodsLists());
                recyclerView.setLayoutManager(new LinearLayoutManager(context));
                recyclerView.setAdapter(pickHomeHotChildHeadAdapter);
                pickHomeHotChildHeadAdapter.setOnItemClick(new PickHomeHotChildHeadAdapter.OnItemClick() {
                    @Override
                    public void onItemClick() {
                        iChildClick.onClick(entity);
                    }
                });
            }
        }

        ImageView imgTab = holder.itemView.findViewById(R.id.img_tab);
        TextView tvType2 = holder.itemView.findViewById(R.id.tv_type2);
        TextView tvEndTime = holder.itemView.findViewById(R.id.tv_endTime);
        TextView name = holder.itemView.findViewById(R.id.name);
        TextView tvType = holder.itemView.findViewById(R.id.tv_type);
        // 招标方式：1、资格预审；2、资格后审；3、报价即报名
        if (null == entity.getVerticalTypeValue()){
            entity.setVerticalTypeValue(0);
        }
        if(entity.getVerticalTypeValue() > 0){
            tvType.setVisibility(View.VISIBLE);
        }else{
            tvType.setVisibility(View.GONE);
        }
        if (1 == entity.getVerticalTypeValue()) {
            tvType.setText("资格预审");
        } else if (2 == entity.getVerticalTypeValue()){
            tvType.setText("资格后审");
        }else if (3 == entity.getVerticalTypeValue()){
            tvType.setText("报名即报价");
        }

        imgTab.setVisibility(View.VISIBLE);
        switch (entity.getStatus()) {
            case "2":
            case "6":
                tvEndTime.setText(String.format("投标结束时间：%s", TextUtils.isEmpty(entity.getEndTime()) ? "" : entity.getEndTime()));
                imgTab.setBackground(context.getResources().getDrawable(R.mipmap.icn_zbz));
                break;
            case "4":
                tvEndTime.setText(String.format("定标时间：%s", TextUtils.isEmpty(entity.getUpdated()) ? "" : entity.getUpdated()));
                imgTab.setBackground(context.getResources().getDrawable(R.mipmap.icn_zbjs));
                break;
            case "9":
                tvEndTime.setText(String.format("报名结束时间：%s", TextUtils.isEmpty(entity.getApplyEndTime()) ? "" : entity.getApplyEndTime()));
                imgTab.setBackground(context.getResources().getDrawable(R.drawable.pick_notice_bmz));
                break;
            case "3":
                tvEndTime.setText(String.format("开标时间：%s", TextUtils.isEmpty(entity.getBidTime()) ? "" : entity.getBidTime()));
                imgTab.setBackground(context.getResources().getDrawable(R.drawable.pick_notice_pbz));
                break;
            case "1":
                tvEndTime.setText(String.format("投标开始时间：%s", TextUtils.isEmpty(entity.getStartTime()) ? "" : entity.getStartTime()));
                imgTab.setBackground(context.getResources().getDrawable(R.drawable.pick_hall_dzb));
                break;
            case "8":
                tvEndTime.setText(String.format("报名开始时间：%s", TextUtils.isEmpty(entity.getEndTime()) ? "" : entity.getEndTime()));
                imgTab.setBackground(context.getResources().getDrawable(R.drawable.pick_notice_dbm));
                break;
        }

        if ("0".equals(type)) {
            tvType2.setText(entity.getTypeName());
            tvType2.setVisibility(View.VISIBLE);
        } else {
            tvType2.setText("");
            tvType2.setVisibility(View.GONE);
        }

        name.setText(entity.getName());

        //新增 “招标轮次”     “报名中”9、“待招标”1状态不显示，其他状态显示    接口判断
        TextView textViewWheel = holder.itemView.findViewById(R.id.tv_wheel_num);
        if (TextUtils.isEmpty(entity.getRotation()) || "0".equals(entity.getRotation()) || "1".equals(entity.getStatus()) || "8".equals(entity.getStatus()) || "9".equals(entity.getStatus())) {
            textViewWheel.setVisibility(View.GONE);
        } else {
            textViewWheel.setVisibility(View.VISIBLE);
            textViewWheel.setText("第" + entity.getRotation() + "轮");
        }
    }

    public void setType(String typeNo) {
        type = typeNo;
    }

    public void onIChildClick(IChildClick iChildClick) {
        this.iChildClick = iChildClick;
    }

    public interface IChildClick {
        void onClick(TenderListEntity tenderListEntity);
    }
}
